<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<% String path=request.getContextPath()+"/";%>
<html>
<head>
    <base href="<%=path%>">
    <title>Title</title>
    <link href="hplus-master//css/bootstrap.min.css?v=3.3.7" rel="stylesheet"/>
    <link href="hplus-master//css/font-awesome.min.css?v=4.4.0" rel="stylesheet"/>
    <link href="hplus-master/css/animate.css" rel="stylesheet"/>
    <link href="hplus-master/css/style.css?v=4.1.0" rel="stylesheet"/>

</head>
<body style="overflow-x: hidden">
<div style="padding: 10px 10px">
    <form class="form-horizontal" id="addForm">
        <input type="hidden" name="deptId" value="${dept.deptId}">
        <div class="form-group">
            <label for="deptName" class="col-sm-2 control-label">部门名称</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" value="${dept.deptName}" id="deptName" name="deptName" placeholder="请输入部门名称">
            </div>
        </div>
        <div class="form-group">
            <label for="deptCode" class="col-sm-2 control-label">部门编号</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" value="${dept.deptCode}"  id="deptCode" name="deptCode" placeholder="请输入部门编号">
            </div>
        </div>

        <div class="form-group">
            <label for="deptMonitor" class="col-sm-2 control-label">部门负责人</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="deptMonitor" value="${dept.deptMonitor}" name="deptMonitor" placeholder="请输入部门负责人姓名">
            </div>
        </div>

        <div class="form-group">
            <label for="status" class="col-sm-2 control-label">状态</label>
            <div class="col-sm-10">
                <select id="status" name="status">

                    <option value="0" <c:if test="${dept.status==0}">selected</c:if>>启用</option>
                    <option value="1" <c:if test="${dept.status==1}">selected</c:if>>停用</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label for="parentId" class="col-sm-2 control-label">所属父级部门</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="parentId" value="${dept.parentId}" name="parentId" placeholder="请输入父级部门编号">
            </div>
        </div>


        <div class="form-group" style="text-align: center">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="btn btn-success save" >保存</button>
                <button type="reset" class="btn btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
</body>
<script src="hplus-master/js/jquery.min.js?v=2.1.4"></script>
<script src="hplus-master/js/bootstrap.min.js?v=3.3.7"></script>
<script src="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.js"></script>
<script src="hplus-master/js/plugins/layer/layer.min.js"></script>
<script src="hplus-master/js/plugins/validate/jquery.validate.min.js"></script>
<script src="hplus-master/js/plugins/validate/messages_zh.min.js"></script>
<script >
    $(function (){
        $("#addForm").validate({
            rules:{
                deptName: {
                    required: true,
                    remote: {
                        url: 'dept/checkDeptName',
                        type: 'post',
                        deptName: function () {
                            return $("#deptName").val();
                        }
                    }
                },
                deptCode:{
                    required:true
                },

                deptMonitor:'required',

            },
            messages:{
                deptName:{
                    required:'<i class=\'fa fa-times-circle\'></i> 请输入部门名称',
                    remote:'部门名称已存在'
                },


            }
        });



        $(".save").click(function(){

            // 对绑定的规则进行校验，如果校验通过，返回true,否则返回false
            if($("#addForm").valid()) {
                let params = $("#addForm").serialize();
                $.ajax({
                    url: 'dept/save',
                    type: 'post',
                    dataType: 'json',
                    data: params,
                    success: function (ret) {

                        if (ret.code == 200) {
                            layer.msg(ret.msg, function () {
                                parent.close();
                            });

                        }
                        if (ret.code != 200) {
                            layer.msg(ret.msg);
                        }

                    }
                })
            }
        });

    })
</script>
</html>
